package com.hexiang.web.err;

import com.hexiang.enums.ResultCodeEnum;
import com.hexiang.web.response.CommonResponse;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * 统一错误码异常处理
 */
@RestControllerAdvice
public class GlobalErrorHandler {

    @ExceptionHandler(value = MethodArgumentNotValidException.class)
    public CommonResponse errorHandlerOverJson(HttpServletRequest request, MethodArgumentNotValidException exception) {
        return CommonResponse.fail(ResultCodeEnum.E015.getCode(), ResultCodeEnum.E015.getMsg());
    }
}
